<?php
include("../../aboutus/model.php");

// ---------------------------------
// controller 
// ---------------------------------
// list every aboutuss by (type, page_num, list_per_page)
// which define by url GET method
$aboutus_list = model_get_aboutus_list();
array_walk($aboutus_list, "set_edit_page");
array_walk($aboutus_list, "set_delete_page");
$body_html = view_aboutus_list($aboutus_list);

include("../template/layout.php");

// ---------------------------------
// model
// ---------------------------------
function set_edit_page(&$value, $key)
{
	$value["edit_page"] = "edit.php?id=" . $value["id"];
}

function set_delete_page(&$value, $key)
{
	$value["delete_page"] = "delete.php?id=" . $value["id"];
}

// ---------------------------------
// view
// ---------------------------------
function view_aboutus_list($aboutus_list)
{
	$aboutus_list_html = "";
	$aboutus_list_html = "<!--aboutus list start-->\n";
	$aboutus_list_html = $aboutus_list_html . "<div class='aboutus_list'>\n";
	foreach ($aboutus_list as $aboutus)
	{
		$aboutus_list_html = $aboutus_list_html .
		view_aboutus(
		$aboutus["name"],
		$aboutus["click_count"],
		$aboutus["edit_page"],
		$aboutus["delete_page"]
		);
	}
	$aboutus_list_html = $aboutus_list_html . "</div>\n";
	$aboutus_list_html = $aboutus_list_html . "<!--aboutus list end-->\n";
	return $aboutus_list_html;
}

function view_aboutus($name, $click_count, $edit_page, $delete_page)
{
	$aboutus_html =
	sprintf("<table class='aboutus_intro'>
		<tr> <td class='aboutus_name'>%s</td></tr>
		<tr> <td class='aboutus_click_count'>点击数:%d</td> </tr>
		<tr> <td class='aboutus_edit'><a href='%s'>编辑</a></td> </tr>
		<tr> <td class='aboutus_delete'><a href='%s'>删除</a></td> </tr>
		</table>",
		$name,
		$click_count,
		$edit_page,
		$delete_page
	);
	return $aboutus_html;
}
?>
